﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace JumJob.Models
{
    public partial class Job
    {
      
       

        public static  IList<Job> search(String query) 
        {
            jum_jobEntities jjDB = new jum_jobEntities();
            return  (from job in jjDB.jum_job
                                         where job.description.Contains(query) || job.jum_category.name.Contains(query)
                                         || job.jum_affiliate.name.Contains(query) || job.posted_by.Contains(query)
                                         select job).ToList();                  
        }

        public String LegacyUser 
        {
            get {
                if (!String.IsNullOrEmpty(posted_by))
                {
                    return posted_by;
                }                    
                else 
                {
                    return jum_affiliate.name;
                }
                    
            }
        }

        public bool isPostedBy(String sessionUser) 
        {
            return posted_by == sessionUser;
        }

        public Bid getAcceptedBid() 
        {
            jum_jobEntities jjDB = new jum_jobEntities();
            Bid accepted = (from bid in jjDB.bid
                            where bid.job_id == id && bid.status == BidStatus.ACEPTADA
                            select bid).FirstOrDefault();
            return accepted;
        }

        public List<Bid> getBids() 
        {
            jum_jobEntities jjDB = new jum_jobEntities();
            List<Bid> bids = (from bid in jjDB.bid
                              where bid.job_id == id
                              select bid).ToList();
            return bids;
        }

    }
}